package com.log.config;

import lombok.Data;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassDescription:
 * @Author: zhaoyi
 * @Created: 2024/7/18 14:17
 */

@Configuration
@Data
public class RabbitMQConfig {

    /**
     * 消息转换器
     * @return
     */
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }



    /**
     * 交换机
     */
    private String logEventExchange = "log_ops_event.exchange";


    /**
     *  队列
     */
    private String logQueue = "log_topic_queue";

    /**
     * 队列路由key
     *
     */
    private String logRoutingKey = "log_routing_key";



    /**
     * 创建交换机 Topic类型
     * @return
     */
    @Bean
    public Exchange logEventExchange(){
        return new TopicExchange(logEventExchange,true,false);
    }


    /**
     * 队列
     */
    @Bean
    public Queue logQueue(){

        return new Queue(logQueue,true,false,false);

    }

    /**
     * 队列的绑定关系建立
     * @return
     */
    @Bean
    public Binding logBinding(){

        return new Binding(logQueue,Binding.DestinationType.QUEUE, logEventExchange,logRoutingKey,null);
    }



}
